package com.caul.demo.hadoop.mapreduce.rank;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * Created by sdliang on 2018/4/11.
 */
public class RankGroupingComparator extends WritableComparator {

  public RankGroupingComparator() {
    super(RankKey.class, true);
  }

  /**
   * 在MapTask阶段,collect聚合时调用: 输出结果为0时会聚合
   *
   * @param a
   * @param b
   * @return
   */
  @Override
  public int compare(WritableComparable a, WritableComparable b) {
    System.out.println(a.toString() + " 对比 " + b.toString());
    return ((RankKey) a).getUid().compareTo(((RankKey) b).getUid());
  }
}
